package com.mxpio.erp.mes.controller;

import com.mxpio.erp.common.mes.entity.ManufactureWorkBatch;
import com.mxpio.erp.common.mes.service.ManufactureWorkBatchService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ManufactureWorkBatchController", description = "生产订单-批次接口")
@RestController
@RequestMapping("/erp/mes/mobatch/")
public class ManufactureWorkBatchController {
	@Autowired
	private ManufactureWorkBatchService service;

	@GetMapping("list")
	@Operation(summary = "生产订单-批次列表", description = "获取生产订单-批次列表", method = "GET")
	public Result<List<ManufactureWorkBatch>> list(Criteria criteria) throws UnsupportedEncodingException {
		List<ManufactureWorkBatch> items = service.list(ManufactureWorkBatch.class, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("page")
	@Operation(summary = "生产订单-批次列表", description = "获取生产订单-批次列表", method = "GET")
	public Result<Page<ManufactureWorkBatch>> page(Criteria criteria, Integer pageSize, Integer pageNo) throws UnsupportedEncodingException {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ManufactureWorkBatch> items = service.listPage(ManufactureWorkBatch.class, page, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("list/{batchCode}")
	@Operation(summary = "根据batchCode获取生产订单-批次", description = "根据batchCode获取生产订单-批次", method = "GET")
	public Result<List<ManufactureWorkBatch>> getByCode(@PathVariable(name = "batchCode", required = true) String batchCode) {
		Criteria criteria = Criteria.create();
		criteria.addCriterion("batchCode", Operator.EQ,batchCode);
		List<ManufactureWorkBatch> list = service.list(ManufactureWorkBatch.class, criteria);
		return Result.OK(list);
	}


}
